package com.link.base.base.mpconfig.controller;

import com.link.base.base.mpconfig.model.MpMenu;
import com.link.base.base.mpconfig.service.MpMenuService;
import com.link.core.cllog.LCLogger;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.basic.service.KeyGenerateService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 小程序菜单基础数据维护
 *
 * @author: 闫有霞
 * @date: 2019/12/19
 */
@Controller
@RequestMapping("/link/mpMenu")
public class MpMenuController extends BasicController<MpMenu> {

    @Resource
    private KeyGenerateService keyGenerateService;

    @Resource
    private MpMenuService mpMenuService;

    @Override
    public BasicService<MpMenu> getBasicService() throws Exception {
        return mpMenuService;
    }
    /**
     *@createdBy 闫有霞
     *@date 2018/12/7
     *@methods: deleteAll
     *@param: MpMenu entity
     *@return: void
     *@description: 级联的删除  即删除一级菜单时删除其子菜单
     **/

    @RequestMapping(value = "/deleteAll")
    @ResponseBody
    public Map<String,Object> deleteAll(@RequestBody  MpMenu entity, HttpSession session,
                                        HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<>();
        try {
            mpMenuService.deleteAll(entity);
            result.put("success", true);
            result.put("result",entity);
        } catch ( Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }

        return result;
    }

    /**
     * @createdBy 闫有霞
     * @date 2018/12/7
     * @methods: updateValidFlag
     * @param:  MpMenu entity
     * @return:  void
     * @description: 更新是否有效
     **/

    @RequestMapping(value = "/updateValidFlag")
    @ResponseBody
    public Map<String,Object> updateValidFlag(@RequestBody  MpMenu entity, HttpSession session,
                                        HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<>();
        try {
            mpMenuService.updateValidFlag(entity);
            result.put("success", true);
            result.put("result",entity);
        } catch ( Exception e ) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }

        return result;
    }
    /**
     *@createdBy 闫有霞
     *@date 2018/12/10
     *@methods: queryMenu
     *@param:   MpMenu
     *@return: result：menuList
     *@description: 查询一级菜单及其对应的二级菜单
     **/

    @RequestMapping(value = "/queryMenu")
    @ResponseBody
    public Map<String,Object> queryMenu(@RequestBody  MpMenu entity, HttpSession session,
                                              HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> result = new HashMap<>();
        try {
            List<MpMenu> menuList = mpMenuService.queryMenu(entity);
            result.put("success", true);
            result.put("result", menuList);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}
